﻿using HarmonyLib;
using RimWorld;
using RimWorld.QuestGen;
using System;
using Verse;

[HarmonyPatch(typeof(CompProjectileInterceptor), "InterceptsProjectile")]
public static class CompProjectileInterceptor_Patch_InterceptsProjectile
{
    private static bool Prefix(CompProjectileInterceptor __instance, ref bool __result, CompProperties_ProjectileInterceptor props, Projectile projectile)
    {
        if (props.interceptAirProjectiles && props.interceptGroundProjectiles)//拦截头顶弹
        {
            __result = true;
            return false;//false才是跳过
        }
        return true;
    }

    //private static void Postfix(CompProjectileInterceptor __instance, ref bool __result, CompProperties_ProjectileInterceptor props, Projectile projectile)
    //{
    //    __result = true;
    //}
}
//[HarmonyPatch(typeof(CompProjectileInterceptor), "BombardmentCanStartFireAt")]
//public static class CompProjectileInterceptor_Patch_BombardmentCanStartFireAt
//{
//    private static bool Prefix(CompProjectileInterceptor __instance, ref bool __result, Bombardment bombardment, IntVec3 cell)
//    {
//        if (!__instance.Active || !__instance.Props.interceptAirProjectiles)
//        {
//            __result =  true;
//        }
//        if ((bombardment.instigator == null || !bombardment.instigator.HostileTo(__instance.parent))  && !__instance.Props.interceptNonHostileProjectiles)
//        {
//            __result =  true;
//        }
//        __result = !cell.InHorDistOf(__instance.parent.Position, __instance.Props.radius);

//        return true;
//    }
//}



//[HarmonyPatch(typeof(CompProjectileInterceptor), "CheckBombardmentIntercept")]
//public static class CompProjectileInterceptor_Patch_CheckBombardmentIntercept
//{
//    private static bool Prefix(CompProjectileInterceptor __instance, ref bool __result, Bombardment bombardment, Bombardment.BombardmentProjectile projectile)
//    {
//        if (!__instance.Active || !__instance.Props.interceptAirProjectiles)
//        {
//            return false;
//        }
//        if (!projectile.targetCell.InHorDistOf(__instance.parent.Position, __instance.Props.radius))
//        {
//            return false;
//        }
//        if ((bombardment.instigator == null || !bombardment.instigator.HostileTo(__instance.parent)) && !__instance.Props.interceptNonHostileProjectiles)//拦截非敌对弹
//        {
//            return false;
//        }

//        return true;
//    }
//}

